package windows;

import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;

import javax.swing.JButton;
import javax.swing.JOptionPane;
import javax.swing.JPanel;

import bussinesmodel.CAdministrator;




public class CAddRestaurantPane extends JPanel 
{
	    private javax.swing.JTextField fieldAddress;
	    private javax.swing.JTextField fieldNit;
	    private javax.swing.JTextField fieldPhone;
	    private javax.swing.JTextField fieldRestaurant;
	    private javax.swing.JLabel labeAddress;
	    private javax.swing.JLabel labePhone;
	    private javax.swing.JLabel labelNit;
	    private javax.swing.JLabel labelRestaurant;
	    private javax.swing.JLabel labelTittle;
	    private javax.swing.JSeparator separadorTitulo;
	    private CAdministrator administrator;
	    private JButton buttonSave;

	    
	    public CAddRestaurantPane() 
	    {
	        initComponents();
	    }
	    
	    
	    private void initComponents() {

	    	buttonSave=new JButton("Save");
	        separadorTitulo = new javax.swing.JSeparator();
	        labelTittle = new javax.swing.JLabel();
	        labelRestaurant = new javax.swing.JLabel();
	        fieldRestaurant = new javax.swing.JTextField();
	        fieldNit = new javax.swing.JTextField();
	        labelNit = new javax.swing.JLabel();
	        labePhone = new javax.swing.JLabel();
	        fieldPhone = new javax.swing.JTextField();
	        labeAddress = new javax.swing.JLabel();
	        fieldAddress = new javax.swing.JTextField();

	        
	        setLayout(null);

	        separadorTitulo.setForeground(new java.awt.Color(0, 0, 0));
	        add(separadorTitulo);
	        separadorTitulo.setBounds(40, 52, 220, 2);

	        labelTittle.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
	        labelTittle.setForeground(new java.awt.Color(0, 0, 102));
	        labelTittle.setText("Ingrese el nuevo Restaurante");
	        add(labelTittle);
	        labelTittle.setBounds(50, 30, 210, 17);

	        labelRestaurant.setText("Nombre Restaurante:");
	        add(labelRestaurant);
	        labelRestaurant.setBounds(40, 90, 140, 14);

	        fieldRestaurant.addActionListener(new java.awt.event.ActionListener() {
	            public void actionPerformed(java.awt.event.ActionEvent evt) {
	               
	            }
	        });
	        add(fieldRestaurant);
	        fieldRestaurant.setBounds(200, 90, 180, 20);

	        fieldNit.addActionListener(new java.awt.event.ActionListener() {
	            public void actionPerformed(java.awt.event.ActionEvent evt) {
	                
	            }
	        });
	        add(fieldNit);
	        fieldNit.setBounds(200, 120, 180, 20);

	        labelNit.setText("                          Nit:");
	        add(labelNit);
	        labelNit.setBounds(50, 120, 100, 14);

	        labePhone.setText("                    Phone:");
	        add(labePhone);
	        labePhone.setBounds(50, 150, 120, 14);

	        fieldPhone.addActionListener(new java.awt.event.ActionListener() {
	            public void actionPerformed(java.awt.event.ActionEvent evt) {
	               
	            }
	        });
	        add(fieldPhone);
	        fieldPhone.setBounds(200, 150, 180, 20);

	        labeAddress.setText("                Direccion:");
	        add(labeAddress);
	        labeAddress.setBounds(50, 180, 130, 14);

	        buttonSave.setText("Guardar");
	        add(buttonSave);
	        buttonSave.setBounds(300, 220, 80, 23);
	        
	        

	        buttonSave.addActionListener(new java.awt.event.ActionListener() 
	        {
	            public void actionPerformed(java.awt.event.ActionEvent evt) 
	            {	
	            	try
	            	{
	            		administrator.saveRestaurant(fieldRestaurant.getText(), fieldNit.getText(),fieldPhone.getText(), fieldAddress.getText());	
	            	}
	            	catch(Exception e)
	            	{
	            		JOptionPane.showMessageDialog(null, "Falta un dato","Error",JOptionPane.ERROR_MESSAGE);
	            	}
	            	
	            	
	            	
	            
	            }
	        });
	        
	        fieldRestaurant.addKeyListener(new KeyAdapter() {
				public void keyTyped(KeyEvent e) {
					char c = e.getKeyChar();
					if ((Character.isDigit(c) || (c == KeyEvent.VK_BACK_SPACE) || (c == KeyEvent.VK_DELETE))) {
					} else {
						String texto = String.valueOf(c);
						e.consume();
						fieldRestaurant.setText(fieldRestaurant.getText()
								+ texto.toUpperCase());
					}
				}
			});
	        
	        
	        fieldAddress.addKeyListener(new KeyAdapter() {
				public void keyTyped(KeyEvent e) {
					char c = e.getKeyChar();
					if ((Character.isDigit(c) || (c == KeyEvent.VK_BACK_SPACE) || (c == KeyEvent.VK_DELETE))) {
					} else {
						String texto = String.valueOf(c);
						e.consume();
						fieldAddress.setText(fieldAddress.getText()
								+ texto.toUpperCase());
					}
				}
			});
	        
	        fieldNit.addKeyListener(new KeyAdapter() {
				public void keyTyped(KeyEvent e) {
					char c = e.getKeyChar();
					if ((Character.isDigit(c) || (c == KeyEvent.VK_BACK_SPACE) || (c == KeyEvent.VK_DELETE))) {
					} else {
						String texto = String.valueOf(c);
						e.consume();
						fieldNit.setText(fieldNit.getText()
								+ texto.toUpperCase());
					}
				}
			});
	        
	        fieldPhone.addKeyListener(new KeyAdapter() {
				public void keyTyped(KeyEvent e) {
					char caracter = e.getKeyChar();
					// Verificar si la tecla pulsada no es un digito
					if (((caracter < '0') || (caracter > '9'))
							&& (caracter != KeyEvent.VK_BACK_SPACE)) {
						e.consume(); // ignorar el evento de teclado
					}
				}
			});
	        
	        
	        add(fieldAddress);
	        fieldAddress.setBounds(200, 180, 180, 20);

	        setLocation(230, 60);
			setSize(400, 500);
	        
	    }


		public void cleanFields()
		{
			fieldAddress.setText("");
			fieldNit.setText("");
			fieldPhone.setText("");
			fieldRestaurant.setText("");
			
			
		}
	    
	    
		public void setAdministrator(CAdministrator administrator) {
			this.administrator = administrator;
		}

	    
	    
	    
	    
}
